I tried to connect with database and get a data to operate but it's gone struck on "pool.query" it can't return value back to outside. I tried a many way to solve but it's can't. So please help me to solve it. Thank you very much for your time.
This is my code Connect to database site:
const mysql = require('mysql');
const express = require('express');
const pool = mysql.createPool({
connectionLimit: 100, //important
host: 'localhost',
user: 'root',
password: 'Edcrfvtgb',
database: 'employeesystem',
debug: false
});
The issue is "It can't return value out from function", T^T
let selectQuery = 'SELECT * FROM ?? ';
let query = mysql.format(selectQuery, ["employee"]);
let dataQuery = '';
const getData = pool.query(query, (err, data) => {
if (err) throw err;
dataQuery = JSON.stringify(data);
dataQuery = JSON.parse(dataQuery);
console.log(dataQuery[1].name);/*Check value and typeof is object*/
});
console.log(dataQuery); /*no value in here*/